NOTE: if you have not yet installed this OSAX, then do it before starting this lesson. The script will not compile without it. Go back to the Requirements section to download the OSAX if you need it.
property crlf : (ASCII character 13) & (ASCII character 10) property http_10_header : "HTTP/1.0 200 OK" & crlf & "Server: WebSTAR/1.0 ID/ACGI" & crlf & ¬ "MIME-Version: 1.0" & crlf & "Content-type: text/html" & crlf & crlf property idletime : 1800 property datestamp : 0 set datestamp to current date on «event WWWΩsdoc» path_args ¬ given «class kfor»:http_search_args, «class post»:post_args, «class meth»:method, « class addr»:client_address, «class user»:username, «class pass»:password, «class frmu»:from_user, « class svnm»:server_name, «class svpt»:server_port, «class scnm»:script_name, « class ctyp»:content_type, «class refr»:referer, «class Agnt»:user_agent, « class Kact»:action, «class Kapt»:action_path, «class Kcip»:client_ip, «class Kfrq»:full_request try set datestamp to current date set return_page to http_10_header ¬ & "<HTML><HEAD><TITLE>Unprocessed Results</TITLE></HEAD>" ¬ & "<BODY><H1>Unprocessed Results</H1>" & return ¬ & "<H4>path_args</H4>" & return & path_args & return ¬ & "<H4>http_search_args</H4>" & return & http_search_args set return_page to return_page & return ¬ & "<H4>post_args</H4>" & return & post_args & return ¬ & "<H4>method</H4>" & return & method & return ¬ & "<H4>client_address</H4>" & return & client_address & return ¬ & "<H4>username</H4>" & return & username & return ¬ & "<H4>password</H4>" & return & password & return set return_page to return_page & return ¬ & "<H4>from_user</H4>" & return & from_user & return ¬ & "<H4>server_name</H4>" & return & server_name & return ¬ & "<H4>server_port</H4>" & return & server_port & return ¬ & "<H4>script_name</H4>" & return & script_name & return ¬ & "<H4>content_type</H4>" & return & content_type & return ¬ & "<H4>referer</H4>" & return & referer & return set return_page to return_page & return ¬ & "<H4>user_agent</H4>" & return & user_agent & return ¬ & "<H4>action</H4>" & return & action & return ¬ & "<H4>action_path</H4>" & return & action_path & return ¬ & "<H4>client_ip</H4>" & return & client_ip & return ¬ & "<H4>full_request</H4>" & return & full_request & return set return_page to return_page ¬ & "<I>Results generated at: " & (current date) ¬ & "</I>" & "</BODY></HTML>" return return_page on error errMsg number errNum set return_page to http_10_header ¬ & "<HTML><HEAD><TITLE>Error Page</TITLE></HEAD>" ¬ & "<BODY><H1>Error Encountered!</H1>" & return ¬ & "An error was encountered while trying to run this script." & return set return_page to return_page ¬ & "<H3>Error Message</H3>" & return & errMsg & return ¬ & "<H3>Error Number</H3>" & return & errNum & return ¬ & "<H3>Date</H3>" & return & (current date) & return set return_page to return_page ¬ & "<HR>Please notify Mr. Webmaster at " ¬ & "<A HREF=\"mailto:webmaster@this.site.com\">webmaster@this.site.com</A>" ¬ & " of this error." & "</BODY></HTML>" return return_page end try end «event WWWΩsdoc» on idle if (current date) > (datestamp + idletime) then quit end if return 5 end idle on quit continue quit end quit
tryThis line, added at the start of the Apple event handler, tells AppleScript that you have provided an error handler (see below) in the event of an error. The usual "try" statement looks like the following:
try [some statements to try to do without error] on error [statements to do if an error occurs] end tryThe "on error" handler is part of the try statement. Therefore, the "end try" line ends the whole statement, including the error handler.
on error errMsg number errNum set return_page to http_10_header ¬ & "<HTML><HEAD><TITLE>Error Page</TITLE></HEAD>" ¬ & "<BODY><H1>Error Encountered!</H1>" & return ¬ & "An error was encountered while trying to run this script." & return set return_page to return_page ¬ & "<H3>Error Message</H3>" & return & errMsg & return ¬ & "<H3>Error Number</H3>" & return & errNum & return ¬ & "<H3>Date</H3>" & return & (current date) & return set return_page to return_page ¬ & "<HR>Please notify Mr. Webmaster at " ¬ & "<A HREF=\"mailto:webmaster@this.site.com\">webmaster@this.site.com</A>" ¬ & " of this error." & "</BODY></HTML>" return return_page end tryThis is the error handling code. If an error occurs after the try statement, this handler is run. It is passed a number of variables. Here we are using just the two standard parameters:
As you can see in the code above, nothing is really new in this handler. All it does is create an HTML page to return that contains the error information. By passing back an HTML page, the user gets two benefits:
Jon Wiederspan
Last Edited: April 26, 1995
Copyright Jon Wiederspan, 1994,1995